/**
 * 文件：activity_add_sample.java
 * 包名：com.ronri.ams.sample;   --- 正式发布时需要修正
 * 说明：轮播组件
 * 作者：MS During
 * 日期：2017/5/9
 * 历史：
 */
package com.ronri.ams.sample;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ListView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cz.nongyetongv5.R;
import com.cz.nongyetongv5.application.InitApplication;
import com.ronri.CustomDialog;
import com.ronri.ams.SystemEnvironmental;
import com.ronri.ams.bean.SampleBean;
import com.ronri.ams.bean.sample_info;
import com.ronri.choosephotos.PhotoItem;
import com.ronri.common.DateUtil;
import com.ronri.list.editview.AbstractItemElement;
import com.ronri.list.editview.DefaultItemElement;
import com.ronri.list.editview.ExtendListEditAdapter;
import com.ronri.list.editview.ListEditAdapter;
import com.ronri.list.editview.PhotoItemElement;
import com.ronri.list.editview.controls.EditCardTextBox;

import java.util.ArrayList;
import java.util.List;

import static com.cz.nongyetongv5.application.InitApplication.gSampleInfo;


public class activity_add_milk_sample extends abstract_activity {

    // 对象
    private ExpandableListView mExpandList = null;

    // 内容
    private List<AbstractItemElement> mItems = new ArrayList<AbstractItemElement>();

    // 句柄
    private Context mContext = null;

    private SampleBean mObject = null;

    private int spoint = -1;

    ExtendListEditAdapter mAdapter = null;

    private TextView mDelete = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_sample);
        Log.i("aaa","activity_add_milk_sample");
        Bundle bundle = getIntent().getExtras();

        String szTitle = bundle.getString("title");
        String szvTitle = bundle.getString("vtitle");

        String szSamples = bundle.getString("data");

        if (szSamples != "") {
            // 生成结果
            mObject = JSONObject.parseObject(szSamples, SampleBean.class);
        }

        mContext = this;

        // 设置标题
        setTitle(szTitle, szvTitle);

        // 初始化内容
        init();

        spoint = bundle.getInt("point");

        // 创建编辑模板
        CreateModule();

        // 获取列表
        mExpandList = (ExpandableListView) findViewById(R.id.list_add_sample);
        mDelete = (TextView)findViewById(R.id.tvDelete);

        mDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                CustomDialog.Builder builder = new CustomDialog.Builder(mContext);
                builder.setMessage("确认删除当前记录吗？");
                builder.setTitle("信息提示");
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();

                        Intent intent = new Intent();
                        Bundle bundle = new Bundle();

                        bundle.putBoolean("delete", true);
                        intent.putExtras(bundle);

                        setResult(RESULT_OK, intent);

                        toFinish();
                    }
                });

                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int i) {
                        dialog.dismiss();
                    }
                });

                builder.create().show();


            }
        });

        if (mExpandList != null) {

            // 隐藏系统箭头
            mExpandList.setGroupIndicator(null);

            mAdapter = new ExtendListEditAdapter(this, mItems, new ListEditAdapter.Callback() {
                @Override
                public void click(View v) {

                }
            });

            mExpandList.setAdapter(mAdapter);


            mExpandList.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
                @Override
                public boolean onGroupClick(ExpandableListView expandableListView, View view, int groupPosition, long id) {
                    switch (groupPosition) {
                        case 0: {

                        }
                        break;
                        case 1: {
                            Intent intent = new Intent(mContext, activity_control_edit_box.class);

                            Bundle bundle = new Bundle();

                            bundle.putInt("edit_layout", R.layout.control_edit_box_barcode);
                            bundle.putInt("resultCode", SystemEnvironmental.PhotoGraph_Memo_Result);
                            bundle.putString("edit_value", mObject.getBarcode());
                            bundle.putString("title", "输入条码");
                            bundle.putString("vtitle", "确定");

                            intent.putExtras(bundle);

                            startActivityForResult(intent, SystemEnvironmental.Sample_INPUT_BARCODE);
                        }
                        break;
                        case 2: {
                            Intent intent = new Intent(mContext, activity_control_edit_box.class);

                            Bundle bundle = new Bundle();

                            bundle.putInt("edit_layout", R.layout.control_edit_box_default);
                            bundle.putInt("resultCode", SystemEnvironmental.PhotoGraph_Memo_Result);
                            bundle.putString("edit_value", mObject.getNum());
                            bundle.putString("title", "输入数量");
                            bundle.putString("vtitle", "确定");

                            intent.putExtras(bundle);

                            startActivityForResult(intent, SystemEnvironmental.Sample_INPUT_NUMBER);
                        }
                        break;
                        case 3: {
                            Intent intent = new Intent(mContext, activity_control_edit_box.class);

                            Bundle bundle = new Bundle();

                            bundle.putInt("edit_layout", R.layout.control_edit_box_default);
                            bundle.putInt("resultCode", SystemEnvironmental.PhotoGraph_Memo_Result);
                            bundle.putString("edit_value", mObject.getBase());
                            bundle.putString("title", "输入基数");
                            bundle.putString("vtitle", "确定");

                            intent.putExtras(bundle);

                            startActivityForResult(intent, SystemEnvironmental.Sample_INPUT_BASE);
                        }
                        break;
                        case 4: {
                            Intent intent = new Intent(mContext, activity_control_edit_box.class);

                            Bundle bundle = new Bundle();

                            bundle.putInt("edit_layout", R.layout.control_edit_box_with_locate);
                            bundle.putInt("resultCode", SystemEnvironmental.Sample_INPUT_ADDRESS);
                            bundle.putString("edit_value", mObject.getAddress());
                            bundle.putString("title", "输入地点");
                            bundle.putString("vtitle", "确定");

                            intent.putExtras(bundle);

                            startActivityForResult(intent, SystemEnvironmental.Sample_INPUT_ADDRESS);
                        }
                        break;
                        case 5: {
                            Intent intent = new Intent(mContext, activity_control_edit_box.class);

                            Bundle bundle = new Bundle();

                            bundle.putInt("edit_layout", R.layout.control_edit_box_voice);
                            bundle.putString("edit_value", mObject.getSource());
                            bundle.putString("title", "输入来源");
                            bundle.putString("vtitle", "确定");

                            intent.putExtras(bundle);

                            startActivityForResult(intent, SystemEnvironmental.Sample_INPUT_SOURCE);
                        }
                        break;
                        case 6: {
                            Intent intent = new Intent(mContext, activity_control_select.class);

                            Bundle bundle = new Bundle();

                            /*** 设置远程地址 ***/
                            bundle.putString("remoteAddress", getResources().getString(R.string.remote_get_sample_nature));
                            bundle.putString("data", "[{\"yes\":1, \"name\":\"是\"},{\"yes\":0, \"name\":\"否\"}]");
                            bundle.putString("filterKeyName", "yes");
                            bundle.putString("viewTitleName", "name");
                            bundle.putInt("control_id", groupPosition);
                            bundle.putInt("selectMode", ListView.CHOICE_MODE_SINGLE);
                            bundle.putString("value", mObject.getHz());
                            // bundle.putString("edit_value", mObject.getHz());
                            bundle.putString("title", "生鲜乳收购许可证");
                            bundle.putString("vtitle", "确定");

                            intent.putExtras(bundle);

                            startActivityForResult(intent, SystemEnvironmental.Sample_INPUT_HZ);
                        }
                        break;
                        case 7: {
                            Intent intent = new Intent(mContext, activity_control_edit_box.class);

                            Bundle bundle = new Bundle();

                            bundle.putInt("edit_layout", R.layout.control_edit_box);
                            bundle.putString("edit_value", mObject.getCardno());
                            bundle.putString("title", "许可证号/备注");
                            bundle.putString("vtitle", "确定");

                            intent.putExtras(bundle);

                            startActivityForResult(intent, SystemEnvironmental.Sample_INPUT_JYZH);
                        }
                        break;

                        case 8: {
                            Intent intent = new Intent(mContext, activity_control_select.class);

                            Bundle bundle = new Bundle();

                            //bundle.putInt("edit_layout", R.layout.control_edit_box);
                            /*** 设置远程地址 ***/
                            bundle.putString("remoteAddress", getResources().getString(R.string.remote_get_sample_nature));
                            bundle.putString("data", "[{\"yes\":1, \"name\":\"是\"},{\"yes\":0, \"name\":\"否\"}]");
                            bundle.putString("filterKeyName", "yes");
                            bundle.putString("viewTitleName", "name");
                            bundle.putInt("control_id", groupPosition);
                            bundle.putInt("selectMode", ListView.CHOICE_MODE_SINGLE);
                            bundle.putString("edit_value", mObject.getBz());
                            bundle.putString("title", "生鲜乳准运证");
                            bundle.putString("vtitle", "确定");

                            intent.putExtras(bundle);

                            startActivityForResult(intent, SystemEnvironmental.Sample_INPUT_YPBZ);
                        }
                        break;
                        case 9: {
                            Intent intent = new Intent(mContext, activity_control_edit_box.class);

                            Bundle bundle = new Bundle();

                            bundle.putInt("edit_layout", R.layout.control_edit_box);
                            bundle.putString("edit_value", mObject.getCyfs());
                            bundle.putString("title", "准运证号/备注");
                            bundle.putString("vtitle", "确定");

                            intent.putExtras(bundle);

                            startActivityForResult(intent, SystemEnvironmental.Sample_INPUT_CYFS);
                        }
                        break;
                        case 10: {
                            Intent intent = new Intent(mContext, activity_control_select.class);

                            Bundle bundle = new Bundle();

                            //bundle.putInt("edit_layout", R.layout.control_edit_box);
                            /*** 设置远程地址 ***/
                            bundle.putString("remoteAddress", getResources().getString(R.string.remote_get_sample_nature));
                            bundle.putString("data", "[{\"yes\":1, \"name\":\"是\"},{\"yes\":0, \"name\":\"否\"}]");
                            bundle.putString("filterKeyName", "yes");
                            bundle.putString("viewTitleName", "name");
                            bundle.putInt("control_id", groupPosition);
                            bundle.putInt("selectMode", ListView.CHOICE_MODE_SINGLE);
                            bundle.putString("edit_value", mObject.getQfbz());
                            bundle.putString("title", "生鲜乳交接单");
                            bundle.putString("vtitle", "确定");

                            intent.putExtras(bundle);

                            startActivityForResult(intent, SystemEnvironmental.Sample_INPUT_QFBZ);
                        }
                        break;
                        case 11: {
                            Intent intent = new Intent(mContext, activity_control_edit_box.class);

                            Bundle bundle = new Bundle();

                            bundle.putInt("edit_layout", R.layout.control_edit_box_voice);
                            bundle.putInt("resultCode", SystemEnvironmental.Sample_INPUT_ADDRESS);
                            bundle.putString("edit_value", mObject.getMemo());
                            bundle.putString("title", "备注");
                            bundle.putString("vtitle", "确定");

                            intent.putExtras(bundle);

                            startActivityForResult(intent, SystemEnvironmental.Sample_INPUT_MEMO);
                        }
                        break;
                        case 12: {
                            Intent intent = new Intent(mContext, activity_photograph.class);

                            Bundle bundle = new Bundle();

                            bundle.putInt("edit_layout", R.layout.control_edit_box);
                            bundle.putInt("resultCode", SystemEnvironmental.Sample_INPUT_PHOTO);
                            bundle.putString("title", "样品拍照");
                            bundle.putString("vtitle", "确定");
                            String szjson = JSON.toJSONString(((PhotoItemElement) mItems.get(12)).GetPhotos());

                            if (szjson != "")
                                bundle.putString("data", szjson);

                            intent.putExtras(bundle);

                            startActivityForResult(intent, SystemEnvironmental.Sample_INPUT_PHOTO);
                        }
                        break;
                    }

                    return false;
                }
            });
        }

    }

    /***
     * 刷新值
     *
     * @param requestCode
     * @param resultCode
     * @param data
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case SystemEnvironmental.Sample_INPUT_BARCODE: {
                    Bundle bundle = data.getExtras();
                    String szResult = bundle.getString("returnValue");
                    mItems.get(1).setInfo(szResult);
                    mAdapter.notifyDataSetChanged();
                    gSampleInfo.getSample_breed().get(spoint).setBar_code(szResult);
                }
                break;
                case SystemEnvironmental.Sample_INPUT_BASE: {
                    Bundle bundle = data.getExtras();
                    String szResult = bundle.getString("returnValue");
                    mItems.get(3).setInfo(szResult);
                    mAdapter.notifyDataSetChanged();
                    gSampleInfo.getSample_breed().get(spoint).setBreed_base(szResult);
                }
                break;
                case SystemEnvironmental.Sample_INPUT_NUMBER: {
                    Bundle bundle = data.getExtras();
                    String szResult = bundle.getString("returnValue");
                    mItems.get(2).setInfo(szResult);
                    mAdapter.notifyDataSetChanged();
                    gSampleInfo.getSample_breed().get(spoint).setBreed_number(szResult);
                }
                break;
                case SystemEnvironmental.Sample_INPUT_ADDRESS: {
                    Bundle bundle = data.getExtras();
                    String szResult = bundle.getString("returnValue");
                    mItems.get(4).setInfo(szResult);
                    mAdapter.notifyDataSetChanged();
                    gSampleInfo.getSample_breed().get(spoint).setSample_location(szResult);
                }
                break;
                case SystemEnvironmental.Sample_INPUT_SOURCE: {
                    Bundle bundle = data.getExtras();
                    String szResult = bundle.getString("returnValue");
                    mItems.get(5).setInfo(szResult);
                    mAdapter.notifyDataSetChanged();
                    gSampleInfo.getSample_breed().get(spoint).setBreed_source(szResult);
                }
                break;
                case SystemEnvironmental.Sample_INPUT_HZ: {
                    Bundle bundle = data.getExtras();
                    String szResult = bundle.getString("returnValue");
                    if (szResult != null){
                        szResult = szResult.replace("[", "");
                        szResult = szResult.replace("]", "");
                        JSONObject jobject = JSONObject.parseObject(szResult);

                        if(jobject.containsKey("yes") == true){
                            if (jobject.getInteger("yes") == 1){
                                mItems.get(6).setInfo("是");
                                mAdapter.notifyDataSetChanged();
                                gSampleInfo.getSample_breed().get(spoint).setBreed_ext1("1");
                            }else{
                                mItems.get(6).setInfo("否");
                                mAdapter.notifyDataSetChanged();
                                gSampleInfo.getSample_breed().get(spoint).setBreed_ext1("0");
                            }
                        }
                    }
//
//                    mItems.get(6).setInfo(szResult);
//                    mAdapter.notifyDataSetChanged();
//                    gSampleInfo.getSample_breed().get(spoint).setBreed_ext1(szResult);
                }
                break;
                case SystemEnvironmental.Sample_INPUT_JYZH: {
                    Bundle bundle = data.getExtras();
                    String szResult = bundle.getString("returnValue");
                    mItems.get(7).setInfo(szResult);
                    mAdapter.notifyDataSetChanged();
                    gSampleInfo.getSample_breed().get(spoint).setBreed_ext2(szResult);
                }
                break;
                case SystemEnvironmental.Sample_INPUT_YPBZ: {
                    Bundle bundle = data.getExtras();
                    String szResult = bundle.getString("returnValue");
                    if (szResult != null){
                        szResult = szResult.replace("[", "");
                        szResult = szResult.replace("]", "");

                        JSONObject jobject = JSONObject.parseObject(szResult);

                        if(jobject.containsKey("yes") == true){
                            if (jobject.getInteger("yes") == 1){
                                mItems.get(8).setInfo("是");
                                mAdapter.notifyDataSetChanged();
                                gSampleInfo.getSample_breed().get(spoint).setBreed_ext3("1");
                            }else{
                                mItems.get(8).setInfo("否");
                                mAdapter.notifyDataSetChanged();
                                gSampleInfo.getSample_breed().get(spoint).setBreed_ext3("0");
                            }
                        }
                    }
                }
                break;
                case SystemEnvironmental.Sample_INPUT_CYFS: {
                    Bundle bundle = data.getExtras();
                    String szResult = bundle.getString("returnValue");
                    mItems.get(9).setInfo(szResult);
                    mAdapter.notifyDataSetChanged();
                    gSampleInfo.getSample_breed().get(spoint).setBreed_ext4(szResult);
                }
                break;
                case SystemEnvironmental.Sample_INPUT_QFBZ: {
                    Bundle bundle = data.getExtras();
                    String szResult = bundle.getString("returnValue");
                    if (szResult != null){
                        szResult = szResult.replace("[", "");
                        szResult = szResult.replace("]", "");
                        JSONObject jobject = JSONObject.parseObject(szResult);

                        if(jobject.containsKey("yes") == true){
                            if (jobject.getInteger("yes") == 1){
                                mItems.get(10).setInfo("是");
                                mAdapter.notifyDataSetChanged();
                                gSampleInfo.getSample_breed().get(spoint).setBreed_ext5("1");
                            }else{
                                mItems.get(10).setInfo("否");
                                mAdapter.notifyDataSetChanged();
                                gSampleInfo.getSample_breed().get(spoint).setBreed_ext5("0");
                            }
                        }
                    }
//
//                    mItems.get(10).setInfo(szResult);
//                    mAdapter.notifyDataSetChanged();
//                    gSampleInfo.getSample_breed().get(spoint).setBreed_ext4(szResult);
                }
                break;
                case SystemEnvironmental.Sample_INPUT_MEMO: {
                    Bundle bundle = data.getExtras();
                    String szResult = bundle.getString("returnValue");
                    mItems.get(11).setInfo(szResult);
                    mAdapter.notifyDataSetChanged();
                    gSampleInfo.getSample_breed().get(spoint).setRemark(szResult);
                }
                break;
                case SystemEnvironmental.Sample_INPUT_PHOTO: {
                    Bundle bundle = data.getExtras();
                    String szResult = bundle.getString("returnValue");
                    if (szResult != "") {
                        List<PhotoItem> lItem = JSONArray.parseArray(szResult, PhotoItem.class);

                        ((PhotoItemElement) mItems.get(12)).SetPhotos(lItem);

                        List<sample_info.SampleBreedBean.BreedAttachBean> lPhoto = new ArrayList<>();

                        for (PhotoItem item : lItem) {
                            sample_info.SampleBreedBean.BreedAttachBean bean = new sample_info.SampleBreedBean.BreedAttachBean();
                            bean.setRemark(item.getMemo());
                            bean.setLocation(item.getAddress());
                            bean.setLatitude(String.valueOf(item.getLatitude()));
                            bean.setLongitude(String.valueOf(item.getLongitude()));
                            bean.setCreate_user(InitApplication.LoginInfo.getData().getUser_id());
                            bean.setAttach_url(item.getUrl());
                            bean.setUpload_date(DateUtil.getCurrentDate("yyyy-MM-dd HH:mm:ss"));

                            lPhoto.add(bean);
                        }

                        gSampleInfo.getSample_breed().get(spoint).setBreed_attach(lPhoto);

                        mAdapter.notifyDataSetChanged();
                    }
                }
                break;
            }
        }
    }

    /***
     * 创建编辑模板
     */
    public void CreateModule() {

        AbstractItemElement iTem = new DefaultItemElement(this,
                "样品名称",
                gSampleInfo.getSample_breed().get(spoint).getBreed_byname(),
                null,
                getResources().getDrawable(R.drawable.jiandujiancha_icon_more),
                "fSampleName",
                "",
                false,
                new EditCardTextBox());

        mItems.add(iTem);

        iTem = new DefaultItemElement(this,
                "样品条码/编码",
                gSampleInfo.getSample_breed().get(spoint).getBar_code(),
                null,
                getResources().getDrawable(R.drawable.jiandujiancha_icon_more),
                "fBarCode",
                "",
                false,
                new EditCardTextBox());

        mItems.add(iTem);


        // 样品数量
        iTem = new DefaultItemElement(this,
                "样品数量",
                gSampleInfo.getSample_breed().get(spoint).getBreed_number(),
                null,
                getResources().getDrawable(R.drawable.jiandujiancha_icon_more),
                "fSampleNumber",
                "",
                false,
                new EditCardTextBox());

        mItems.add(iTem);

        // 样品基数
        iTem = new DefaultItemElement(this,
                "样品基数",
                gSampleInfo.getSample_breed().get(spoint).getBreed_base(),
                null,
                getResources().getDrawable(R.drawable.jiandujiancha_icon_more),
                "fSampleBase",
                "",
                false,
                new EditCardTextBox());

        mItems.add(iTem);

        // 样品基数
        iTem = new DefaultItemElement(this,
                "抽样地点",
                gSampleInfo.getSample_breed().get(spoint).getSample_location(),
                null,
                getResources().getDrawable(R.drawable.jiandujiancha_icon_more),
                "fSampleLocate",
                "",
                false,
                new EditCardTextBox());

        mItems.add(iTem);

        // 样品来源
        iTem = new DefaultItemElement(this,
                "样品来源",
                gSampleInfo.getSample_breed().get(spoint).getBreed_source(),
                null,
                getResources().getDrawable(R.drawable.jiandujiancha_icon_more),
                "fSampleSource",
                "",
                false,
                new EditCardTextBox());

        mItems.add(iTem);


        // 规格型号/备注
        iTem = new DefaultItemElement(this,
                "生鲜乳收购许可证",
                gSampleInfo.getSample_breed().get(spoint).getBreed_ext1(),
                null,
                getResources().getDrawable(R.drawable.jiandujiancha_icon_more),
                "fMemo",
                "",
                false,
                new EditCardTextBox());

        mItems.add(iTem);


        // 规格型号/备注
        iTem = new DefaultItemElement(this,
                "许可证号/备注",
                gSampleInfo.getSample_breed().get(spoint).getBreed_ext2(),
                null,
                getResources().getDrawable(R.drawable.jiandujiancha_icon_more),
                "fMemo",
                "",
                false,
                new EditCardTextBox());

        mItems.add(iTem);


        // 规格型号/备注
        iTem = new DefaultItemElement(this,
                "生鲜乳准运证",
                gSampleInfo.getSample_breed().get(spoint).getBreed_ext3(),
                null,
                getResources().getDrawable(R.drawable.jiandujiancha_icon_more),
                "fMemo",
                "",
                false,
                new EditCardTextBox());

        mItems.add(iTem);

        // 规格型号/备注
        iTem = new DefaultItemElement(this,
                "准运证号/备注",
                gSampleInfo.getSample_breed().get(spoint).getBreed_ext4(),
                null,
                getResources().getDrawable(R.drawable.jiandujiancha_icon_more),
                "fMemo",
                "",
                false,
                new EditCardTextBox());

        mItems.add(iTem);

        // 规格型号/备注
        iTem = new DefaultItemElement(this,
                "生鲜乳交接单",
                gSampleInfo.getSample_breed().get(spoint).getBreed_ext5(),
                null,
                getResources().getDrawable(R.drawable.jiandujiancha_icon_more),
                "fMemo",
                "",
                false,
                new EditCardTextBox());

        mItems.add(iTem);

        // 规格型号/备注
        iTem = new DefaultItemElement(this,
                "备注",
                gSampleInfo.getSample_breed().get(spoint).getRemark(),
                null,
                getResources().getDrawable(R.drawable.jiandujiancha_icon_more),
                "fMemo",
                "",
                false,
                new EditCardTextBox());

        mItems.add(iTem);

        // 样品拍照
        iTem = new PhotoItemElement(this,
                "样品拍照",
                "",
                null,
                getResources().getDrawable(R.drawable.jiandujiancha_icon_more),
                "fPhotos",
                "",
                false);


        List<PhotoItem> lPhoto = new ArrayList<PhotoItem>();

        if (gSampleInfo.getSample_breed().get(spoint).getBreed_attach() == null)
            gSampleInfo.getSample_breed().get(spoint).setBreed_attach(new ArrayList<sample_info.SampleBreedBean.BreedAttachBean>());

        for (sample_info.SampleBreedBean.BreedAttachBean ii : gSampleInfo.getSample_breed().get(spoint).getBreed_attach()) {

            PhotoItem photoItem = new PhotoItem();

            photoItem.PhotoPath = ii.getAttach_name();

            photoItem.setUrl(ii.getAttach_url());
            photoItem.setAddress(ii.getLocation());
            photoItem.setLatitude(Double.valueOf(ii.getLatitude()));
            photoItem.setLongitude(Double.valueOf(ii.getLongitude()));
            photoItem.setMemo(ii.getRemark());

            lPhoto.add(photoItem);
        }

        ((PhotoItemElement) iTem).SetPhotos(lPhoto);

        mItems.add(iTem);
    }

    /***
     * 放弃返回
     *
     * @return
     */
    @Override
    public boolean CancelReturn() {
        Intent intent = new Intent();
        Bundle bundle =  new Bundle();

        bundle.putInt("point", spoint);
        intent.putExtras(bundle);

        setResult(RESULT_CANCELED, intent);
        return super.CancelReturn();
    }

    /***
     * 成功返回
     *
     * @return
     */
    @Override
    public boolean SureReturn() {
        Intent intent = new Intent();
        Bundle bundle = new Bundle();

        bundle.putString("returnValue", JSONObject.toJSONString(mObject));
        intent.putExtras(bundle);

        setResult(RESULT_OK, intent);

        return super.SureReturn();
    }
}
